#include <QCoreApplication>
#include<QSemaphore>
#include<QThread>
#include<iostream>
using namespace std;

const int datasize=100;
const int buffersize=0;

QSemaphore freespace(buffersize);
QSemaphore usespace(0);

class produce:public QThread
{

private:

protected:
    void run();
private:

public:

};

void produce::run()
{
    for(int i=0;i<datasize;i++)
    {
        freespace.acquire();
        std::cerr<<i<<"---produce";
        usespace.release();

    }
}

class consumer:public QThread
{

private:

protected:
    void run();
private:

public:


};

void consumer::run()
{
    for(int i=0;i<datasize;i++)
    {
        freespace.release();
        std::cerr<<i<<"---consumer\n";
        usespace.acquire();

    }
}


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    produce p;
    consumer c;
    p.start();
    c.start();
    p.wait();
    c.wait();

    return a.exec();
}
